
package com.wit.witmg.util;

import lombok.Data;

import java.io.Serializable;

/**
 * JSON回应类
 *
 */
@Data
public class JsonResult implements Serializable {

    private Integer result = 1;// 1成功,-1失败
    private Integer code=0;//错误码
    private Object message = "成功";  // 提示语
//    private long total;// 数据总数
    /**
     * 构造函数
     */
    public JsonResult() {
    }


    public JsonResult(Object message) {
        this.message = message;
    }


    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.message = msg;
    }

    public JsonResult(Integer result,Integer code, Object msg) {
        this.result = result;
        this.code = code;
        this.message = msg;
    }


    public static JsonResult success() {
        return new JsonResult();
    }

    public static JsonResult success(Object msg) {
        return new JsonResult(msg);
    }

    public static JsonResult success(ErrorCode errorCode) {
        return new JsonResult(1,errorCode.getCode(),errorCode.getMsg());
    }

    public static JsonResult error(Object msg) {
        return new JsonResult(-1,0,msg);
    }

    public static JsonResult error(int code,Object msg) {
        return new JsonResult(-1,code,msg);
    }

    public static JsonResult error(ErrorCode errorCode) {
        return new JsonResult(-1,errorCode.getCode(), errorCode.getMsg());
    }


}
